package com.atguigu.ssm.service.impl;

import com.atguigu.ssm.mapper.EmployeeMapper;
import com.atguigu.ssm.pojo.Employee;
import com.atguigu.ssm.service.EmployeeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional(timeout = 10,rollbackFor = Exception.class)
public class EmployeeServiceImpl implements EmployeeService {
    @Autowired
    private EmployeeMapper employeeMapper;
    @Override
    public Employee queryEmployeeOne(int empId) {
        return employeeMapper.queryEmployeeOne(empId);
    }

    @Override
    public PageInfo<Employee> findPages(int pageNum, int pageSize) {
        // 开启分页功能
        PageHelper.startPage(pageNum,pageSize);
        // 查询所有员工信息
        List<Employee> employees = employeeMapper.selectAll();
        // 获取分页相关数据
        PageInfo<Employee> pageInfo = new PageInfo<>(employees);
        return pageInfo;
    }
}
